package com.sia.springcloud.controller;

import com.sia.springcloud.service.ICollectService;
import com.sia.springcloud.result.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: Sirius
 * @Date: 2021/12/21 1:15
 * @Description:
 **/
@Slf4j
@RestController
public class CollectController implements ICollectController {

    @Resource
    private ICollectService collectService;

    /**
     * 开启指定设备的数采
     *
     * @param request
     * @return
     */
    @Override
    public String startCollect(HttpServletRequest request) {
        String deviceId = request.getParameter("deviceId");

        boolean startCollect = collectService.startCollect(deviceId);

        if (startCollect) {
            return ResultUtil.createSimpleSuccessJson("数采开启成功");
        } else {
            return ResultUtil.createSimpleFailureJson("数采开启失败");
        }
    }


    /**
     * 关闭指定设备的数采
     *
     * @param request
     * @return
     */
    @Override
    public String stopCollect(HttpServletRequest request) {
        String deviceId = request.getParameter("deviceId");

        boolean stopCollect = collectService.stopCollect(deviceId);

        if (stopCollect) {
            return ResultUtil.createSimpleSuccessJson("数采关闭成功");
        } else {
            return ResultUtil.createSimpleFailureJson("数采关闭失败");
        }
    }


    /**
     * 进入写变量方法
     *
     * @param request
     * @return
     */
    @Override
    public String writeVariable(HttpServletRequest request) {
        String deviceId = request.getParameter("deviceId");
        String value = request.getParameter("value");
        return ResultUtil.createSimpleFailureJson("数据写入失败");
    }
}
